Convert all profiler times from nsec to usec
authorAlexander Larsson <alexl@redhat.com>
Wed, 12 Feb 2020 09:44:17 +0000 (10:44 +0100)
committerAlexander Larsson <alexl@redhat.com>
Wed, 12 Feb 2020 09:44:17 +0000 (10:44 +0100)
usec is the scale of the monotonic timer which is where we get almost
all the times from. The only actual source of nsec is the opengl
GPU time (but who knows what the actual resulution of that is).

Changing this to usec allows us to get rid of " * 1000" in a *lot* of
places all over the codebase, which are ugly and confusing.

19 files changed:
gdk/gdkdrawcontext.c
gdk/gdkframeclock.c
gdk/gdkframeclockidle.c
gdk/gdkprofiler.c
gdk/gdksurface.c
gdk/wayland/gdkdisplay-wayland.c
gdk/wayland/gdkglcontext-wayland.c
gdk/wayland/gdksurface-wayland.c
gsk/gl/gskglprofiler.c
gsk/gl/gskglrenderer.c
gsk/gskprofiler.c
gtk/gtkapplication.c
gtk/gtkbuilderparser.c
gtk/gtkcssnode.c
gtk/gtkcssprovider.c
gtk/gtkemojichooser.c
gtk/gtkicontheme.c
gtk/gtkwidget.c
gtk/gtkwindow.c

index 93f85528e6d6b24cc4954bf3bdbbd7e401045bab..5c25d8740756bfae9cd62956458968d8c2a9adb3 100644 (file)
@@ -385,7 +385,7 @@ gdk_draw_context_end_frame (GdkDrawContext *context)
 #ifdef G_ENABLE_DEBUG
   if (gdk_profiler_is_running ())
     gdk_profiler_set_int_counter (pixels_counter,
-                                  g_get_monotonic_time () * 1000,
+                                  g_get_monotonic_time (),
                                   region_get_pixels (priv->frame_region));
 #endif
 
index 272edbe4f6b11e5a75d798c1d6f52da0f78dae74..de5deb887acbf09e4db8c37244f572f63c5e70f0 100644 (file)
@@ -654,7 +654,7 @@ _gdk_frame_clock_emit_flush_events (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "flush-events");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "flush-events");
     }
 }
 
@@ -668,7 +668,7 @@ _gdk_frame_clock_emit_before_paint (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "before-paint");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "before-paint");
     }
 }
 
@@ -682,7 +682,7 @@ _gdk_frame_clock_emit_update (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "update");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "update");
     }
 }
 
@@ -696,7 +696,7 @@ _gdk_frame_clock_emit_layout (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "layout");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "layout");
     }
 }
 
@@ -710,7 +710,7 @@ _gdk_frame_clock_emit_paint (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "paint");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "paint");
     }
 }
 
@@ -724,7 +724,7 @@ _gdk_frame_clock_emit_after_paint (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "after-paint");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "after-paint");
     }
 }
 
@@ -738,7 +738,7 @@ _gdk_frame_clock_emit_resume_events (GdkFrameClock *frame_clock)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "resume-events");
+      gdk_profiler_add_mark (before, (after - before), "frameclock", "resume-events");
     }
 }
 
@@ -818,9 +818,9 @@ _gdk_frame_clock_add_timings_to_profiler (GdkFrameClock   *clock,
 {
   if (timings->presentation_time != 0)
     {
-      gdk_profiler_add_mark (timings->presentation_time * 1000, 0, "frameclock", "presentation");
+      gdk_profiler_add_mark (timings->presentation_time, 0, "frameclock", "presentation");
       gdk_profiler_set_counter (fps_counter,
-                                timings->presentation_time * 1000,
+                                timings->presentation_time,
                                 frame_clock_get_fps (clock)); 
     }
 }
index 29cd57975ffae8a8b56831c7f5fc0d727c95c99f..b350924ce2522c6a675dee6f687ca161788ba755 100644 (file)
@@ -502,7 +502,7 @@ gdk_frame_clock_paint_idle (void *data)
     priv->sleep_serial = get_sleep_serial ();
 
   if (gdk_profiler_is_running ())
-    gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "frameclock", "paint_idle");
+    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "frameclock", "paint_idle");
 
   return FALSE;
 }
@@ -599,8 +599,8 @@ gdk_frame_clock_idle_thaw (GdkFrameClock *clock)
           if (priv->freeze_time != 0)
             {
               gint64 thaw_time = g_get_monotonic_time ();
-              gdk_profiler_add_mark (priv->freeze_time * 1000,
-                                     (thaw_time - priv->freeze_time) * 1000,
+              gdk_profiler_add_mark (priv->freeze_time,
+                                     (thaw_time - priv->freeze_time),
                                      "frameclock freeze", "");
               priv->freeze_time = 0;
             }
index d7eeaa1d526219d18f9a6d92d9d0a6271db5dcba..81288be1737b2f22bba9a2c71179658a2e1d0cb3 100644 (file)
@@ -94,9 +94,9 @@ gdk_profiler_add_mark (gint64      start,
     return;
 
   sysprof_capture_writer_add_mark (writer,
-                                   start,
+                                   start * 1000L,
                                    -1, getpid (),
-                                   duration,
+                                   duration * 1000L,
                                    "gtk", name, message);
 }
 
@@ -118,9 +118,9 @@ gdk_profiler_add_markf (gint64      start,
   va_end (args);
 
   sysprof_capture_writer_add_mark (writer,
-                                   start,
+                                   start * 1000L,
                                    -1, getpid (),
-                                   duration,
+                                   duration * 1000L,
                                    "gtk", name, message);
   g_free (message);
 }
@@ -178,7 +178,7 @@ gdk_profiler_set_counter (guint  id,
 
   value.vdbl = val;
   sysprof_capture_writer_set_counters (writer,
-                                       time,
+                                       time * 1000L,
                                        -1, getpid (),
                                        &id, &value, 1);
 }
@@ -195,7 +195,7 @@ gdk_profiler_set_int_counter (guint  id,
 
   value.v64 = val;
   sysprof_capture_writer_set_counters (writer,
-                                       time,
+                                       time * 1000L,
                                        -1, getpid (),
                                        &id, &value, 1);
 }
index 9725e03bc6560ee5fb10d44aa13d21efc82b8ca1..9c95736aed4092f6c457a84ac7c583858b666748 100644 (file)
@@ -4103,9 +4103,9 @@ add_event_mark (GdkEvent *event,
     }
 
   if (kind != NULL && message != NULL)
-    gdk_profiler_add_markf (time * 1000L, duration * 1000L, "event", "%s %s", kind, message);
+    gdk_profiler_add_markf (time, duration, "event", "%s %s", kind, message);
   else
-    gdk_profiler_add_mark (time * 1000L, duration * 1000L, "event", message ? message : kind);
+    gdk_profiler_add_mark (time, duration, "event", message ? message : kind);
 
   g_free (message);
 }
index 10c4445c36b74189edb50fa7a50fb6b46b837a82..59ffdea73c488bc5add09da84c9aaf8cc994e114 100644 (file)
@@ -1155,7 +1155,7 @@ _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland)
 
   if (gdk_profiler_is_running ())
     {
-      gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "wayland", "load cursor theme");
+      gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "wayland", "load cursor theme");
     }
 
 }
index ec647c77643c55f6dad6b1b1665203521134eb79..0b9dbb5da70a9f708a17f48a474c9608615987ff 100644 (file)
@@ -239,7 +239,7 @@ gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
   gdk_wayland_surface_sync (surface);
   gdk_wayland_surface_request_frame (surface);
 
-  gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "swap buffers");
+  gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "swap buffers");
   if (display_wayland->have_egl_swap_buffers_with_damage)
     {
       int i, j, n_rects = cairo_region_num_rectangles (painted);
index 4850bafd8ad67aeb1b8e3ab914174dd4959d4590..58d94881a14db3088ca4900724a35b88de9f7ed1 100644 (file)
@@ -357,7 +357,7 @@ frame_callback (void               *data,
   GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
   GdkFrameTimings *timings;
 
-  gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "frame event");
+  gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "frame event");
   GDK_DISPLAY_NOTE (GDK_DISPLAY (display_wayland), EVENTS, g_message ("frame %p", surface));
 
   wl_callback_destroy (callback);
@@ -478,7 +478,7 @@ on_frame_clock_after_paint (GdkFrameClock *clock,
        * before we need to stage any changes, then we can take it back and
        * use it again.
        */
-      gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "surface commit");
+      gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "surface commit");
       wl_surface_commit (impl->display_server.wl_surface);
 
       impl->pending_commit = FALSE;
@@ -1510,7 +1510,7 @@ gdk_wayland_surface_create_xdg_toplevel (GdkSurface *surface)
   if (impl->hint == GDK_SURFACE_TYPE_HINT_DIALOG)
     _gdk_wayland_screen_add_orphan_dialog (surface);
 
-  gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "surface commit");
+  gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "surface commit");
   wl_surface_commit (impl->display_server.wl_surface);
 }
 
@@ -2305,7 +2305,7 @@ gdk_wayland_surface_create_xdg_popup (GdkSurface     *surface,
         }
     }
 
-  gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "surface commit");
+  gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "surface commit");
   wl_surface_commit (impl->display_server.wl_surface);
 
   impl->popup_parent = parent;
index 0d58ee89d1eee45bfd6fffab623e7506ba1a2bab..95f5a794a52175368268a1b7ab38cd3fd1c167f2 100644 (file)
@@ -171,5 +171,5 @@ gsk_gl_profiler_end_gpu_region (GskGLProfiler *profiler)
   else
     elapsed = 0;
 
-  return elapsed;
+  return elapsed / 1000; /* Convert to usec to match other profiler APIs */
 }
index cb88c8ca7186a248efc6d100088652e2d0b1ceab..b1556f831f1c123ea832998a707419f1846e4735 100644 (file)
@@ -2858,7 +2858,7 @@ gsk_gl_renderer_realize (GskRenderer  *renderer,
   gsk_gl_shadow_cache_init (&self->shadow_cache);
 
   if (gdk_profiler_is_running ())
-    gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "gl renderer realize", NULL);
+    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gl renderer realize", NULL);
 
   return TRUE;
 }
index a18362a6c8b4936e3c9c23b5be7b6e41022668d8..e9ef91af93682019ec56819ebe9126ad0876153f 100644 (file)
@@ -262,7 +262,7 @@ gsk_profiler_timer_begin (GskProfiler *profiler,
     return;
 
   timer->in_flight = TRUE;
-  timer->start_time = g_get_monotonic_time () * 1000;
+  timer->start_time = g_get_monotonic_time ();
 }
 
 gint64
@@ -289,7 +289,7 @@ gsk_profiler_timer_end (GskProfiler *profiler,
       return 0;
     }
 
-  diff = (g_get_monotonic_time () * 1000) - timer->start_time;
+  diff = g_get_monotonic_time () - timer->start_time;
 
   timer->in_flight = FALSE;
   timer->value += diff; 
@@ -360,7 +360,7 @@ gsk_profiler_timer_get (GskProfiler *profiler,
     }
 
   if (timer->invert)
-    return (gint64) (1000000000.0 / (double) timer->value);
+    return (gint64) (1000000.0 / (double) timer->value);
 
   return timer->value;
 }
@@ -437,7 +437,7 @@ gsk_profiler_push_samples (GskProfiler *profiler)
       s->id = timer->id;
 
       if (timer->invert)
-        s->value = (gint64) (1000000000.0 / (double) timer->value);
+        s->value = (gint64) (1000000.0 / (double) timer->value);
       else
         s->value = timer->value;
     }
@@ -506,20 +506,19 @@ gsk_profiler_append_timers (GskProfiler *profiler,
     {
       NamedTimer *timer = value_p;
       const char *unit = timer->invert ? "" : "usec";
-      double scale = timer->invert ? 1.0 : 1000.0;
 
       g_string_append_printf (buffer, "%s (%s): %.2f",
                               timer->description,
                               unit,
-                              (double) timer->value / scale);
+                              (double) timer->value);
 
       if (timer->n_samples > 1)
         {
           timer->avg_value = timer->avg_value / timer->n_samples;
           g_string_append_printf (buffer, " Min: %.2f Avg: %.2f Max: %.2f (%" G_GINT64_FORMAT " samples)",
-                                  (double) timer->min_value / scale,
-                                  (double) timer->avg_value / scale,
-                                  (double) timer->max_value / scale,
+                                  (double) timer->min_value,
+                                  (double) timer->avg_value,
+                                  (double) timer->max_value,
                                   timer->n_samples);
         }
 
index a60feee9e5f645e5e5e8015fda9d128bc04d23b5..6885c4e44f872abb57adfa74093b23a96b746cf2 100644 (file)
@@ -307,7 +307,7 @@ gtk_application_startup (GApplication *g_application)
   before2 = g_get_monotonic_time ();
   gtk_init ();
   if (gdk_profiler_is_running ())
-    gdk_profiler_add_mark (before2 * 1000, (g_get_monotonic_time () - before2) * 1000, "gtk init", NULL);
+    gdk_profiler_add_mark (before2, (g_get_monotonic_time () - before2), "gtk init", NULL);
 
   priv->impl = gtk_application_impl_new (application, gdk_display_get_default ());
   gtk_application_impl_startup (priv->impl, priv->register_session);
@@ -315,7 +315,7 @@ gtk_application_startup (GApplication *g_application)
   gtk_application_load_resources (application);
 
   if (gdk_profiler_is_running ())
-    gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "gtk application startup", NULL);
+    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gtk application startup", NULL);
 }
 
 static void
index 7b781c17d12bdf173694d26648b7a0b6eb076388..6247f53f9dce7e0f32a566baacb629df53bd73d2 100644 (file)
@@ -1625,5 +1625,5 @@ _gtk_builder_parser_parse_buffer (GtkBuilder   *builder,
   /* restore the original domain */
   gtk_builder_set_translation_domain (builder, domain);
 
-  gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "builder load", filename);
+  gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "builder load", filename);
 }
index 49324479559e0ffeb5f6c933c7f96dc8b2400182..03fd29a79563864d7dcfd2983ac22dd445b4d096 100644 (file)
@@ -1354,9 +1354,9 @@ gtk_css_node_validate (GtkCssNode *cssnode)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "css validation", "");
-      gdk_profiler_set_int_counter (invalidated_nodes_counter, after * 1000, invalidated_nodes);
-      gdk_profiler_set_int_counter (created_styles_counter, after * 1000, created_styles);
+      gdk_profiler_add_mark (before, (after - before), "css validation", "");
+      gdk_profiler_set_int_counter (invalidated_nodes_counter, after, invalidated_nodes);
+      gdk_profiler_set_int_counter (created_styles_counter, after, created_styles);
       invalidated_nodes = 0;
       created_styles = 0;
     }
index 9d26e7172c1361a82d2b5abd5f50835df5c22f5d..986d38a40dd4a503f2749d1578d0e79451eca0ef 100644 (file)
@@ -1010,7 +1010,7 @@ gtk_css_provider_postprocess (GtkCssProvider *css_provider)
 #endif
 
   if (gdk_profiler_is_running ())
-    gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "create selector tree", NULL);
+    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "create selector tree", NULL);
 }
 
 static void
@@ -1071,7 +1071,7 @@ gtk_css_provider_load_internal (GtkCssProvider *self,
   if (gdk_profiler_is_running ())
     {
       char *uri = g_file_get_uri (file);
-      gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "theme load", uri);
+      gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "theme load", uri);
       g_free (uri);
     }
 }
index f546b9f3a300404aa040d8828f3cb0f5e74fa2d5..a82eaf9e2edccb889af4f19000be737a70fbda54 100644 (file)
@@ -466,7 +466,7 @@ populate_emoji_chooser (gpointer data)
       if (now > start + 8000)
         {
           if (gdk_profiler_is_running ())
-            gdk_profiler_add_mark (start * 1000, (now - start) * 1000, "emojichooser", "populate");
+            gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate");
           return G_SOURCE_CONTINUE;
         }
     }
@@ -479,7 +479,7 @@ populate_emoji_chooser (gpointer data)
   if (gdk_profiler_is_running ())
     {
       now = g_get_monotonic_time ();
-      gdk_profiler_add_mark (start * 1000, (now - start) * 1000, "emojichooser", "populate (finish)");
+      gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate (finish)");
     }
 
   return G_SOURCE_REMOVE;
index aec4b78b4a4003bfca51ca0175751fb61a9f15f3..398f5558de98652e7642b7c1a6c33701d0b18967 100644 (file)
@@ -1847,7 +1847,7 @@ ensure_valid_themes (GtkIconTheme *self,
       load_themes (self);
 
       if (gdk_profiler_is_running ())
-        gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "icon theme load", self->current_theme);
+        gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "icon theme load", self->current_theme);
 
       if (was_valid)
         queue_theme_changed (self);
@@ -3606,7 +3606,8 @@ icon_ensure_texture__locked (GtkIconPaintable *icon,
   g_assert (icon->texture != NULL);
 
   if (gdk_profiler_is_running ())
-    gdk_profiler_add_markf (before * 1000, (g_get_monotonic_time () - before) * 1000, in_thread ?  "icon load (thread)" : "icon load" , "%s size %d@%d", icon->filename, icon->desired_size, icon->desired_scale);
+    gdk_profiler_add_markf (before, g_get_monotonic_time () - before, in_thread ?  "icon load (thread)" : "icon load" ,
+                            "%s size %d@%d", icon->filename, icon->desired_size, icon->desired_scale);
 }
 
 static GdkTexture *
index 70e59ce60aab799c4f50c58c47a9760327643abc..294a5d6b19c035f6e07584158a06c24611d56925 100644 (file)
@@ -12196,7 +12196,7 @@ gtk_widget_render (GtkWidget            *widget,
   if (gdk_profiler_is_running ())
     {
       after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "widget snapshot", "");
+      gdk_profiler_add_mark (before, (after - before), "widget snapshot", "");
     }
 
   if (root != NULL)
@@ -12215,7 +12215,7 @@ gtk_widget_render (GtkWidget            *widget,
         {
           before = after;
           after = g_get_monotonic_time ();
-          gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "widget render", "");
+          gdk_profiler_add_mark (before, (after - before), "widget render", "");
         }
     }
 }
index c2b8a9fe4e64918bd8e66e37755cf4cda4a7a52b..5f179d0c99cafb0aac266b57df5428de31193a0b 100644 (file)
@@ -6319,7 +6319,7 @@ gtk_window_check_resize (GtkWindow *self)
   if (gdk_profiler_is_running ())
     {
       gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "size allocation", "");
+      gdk_profiler_add_mark (before, (after - before), "size allocation", "");
     }
 }